package com.cjl.jvm.gc;

import com.cjl.designpattern.memento.actualcombat.Sys;

import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;

public class ReferenceMaster {
    private static final int _1MB = 1024 * 1024;

    public ReferenceMaster(int i) {
        byte[] allocation1;
        allocation1 = new byte[i * _1MB];
    }

    public void info(){
        System.out.println("ReferenceMaster.info");
    }

    public static void main(String[] args) throws InterruptedException {

        SoftReference<ReferenceMaster> weakReference = new SoftReference<ReferenceMaster>(new ReferenceMaster(99));
//        WeakReference<ReferenceMaster> weakReference2 = new WeakReference<ReferenceMaster>(new ReferenceMaster(100));
        System.gc();
        Thread.sleep(500);
        if (weakReference.get() != null){
            weakReference.get().info();
        }else {
            System.out.println("ReferenceMaster.main weakReference.get() null");
        }
//        if (weakReference2.get() != null){
//            weakReference2.get().info();
//        }else {
//            System.out.println("ReferenceMaster.main weakReference2.get() null");
//        }

//        ReferenceMaster referenceMaster = new ReferenceMaster();
//        ReferenceMaster referenceMaster2 = new ReferenceMaster();

    }


}
